REM THIS SCRIPT ASSUMES THE FOLLOWING
REM 1) The 3 projects (Control, Design and VSIX are in sibling folders and have this naming format)
REM   Contol = xxxxx
REM   Design = xxxxx.Design
REM   VSIX   = xxxxx.VSIX
REM 2) SDKManifest.XML is in the root of the Control project
REM 3) Contol has optional dependencies DEP1 and DEP2 that are copied explicitly defined below
REM    If no depencencies, simply REM those lines
REM
REM In post build, add the following lines. The script depends on these env variables.
REM set root=$(SolutionDir)..
REM set config=$(ConfigurationName)
REM set namespace=$(SolutionName)
REM call "$(ProjectDir)UpdateVSIX.cmd"

if "%root%" EQU "" ( goto :CONFIGERROR )
if "%config%" EQU "" ( goto :CONFIGERROR )
if "%namespace%" EQU "" ( goto :CONFIGERROR )
goto :START

:CONFIGERROR
set %ERRORLEVEL%=1
echo The post build script to Update VSIX is not setup correctly.
GOTO :EOF

:START
setlocal

REM set DEP1=%root%\OhZeeCreative.Core\bin\%config%\OhZeeCreative.Core.dll
REM set DEP2=%root%\OhZeeCreative.Windows8\bin\%config%\OhZeeCreative.Windows8.dll

set VSIXROOT=%root%\%namespace%.VSIX
echo VSIXROOT="%VSIXROOT%"

set REFERENCES=%VSIXROOT%\References\CommonConfiguration\neutral
echo REFERENCES="%REFERENCES%"

set REDIST=%VSIXROOT%\Redist\CommonConfiguration\neutral
echo REDIST="%REDIST%"

set DESIGNTIME=%VSIXROOT%\DesignTime\CommonConfiguration\neutral
echo DESIGNTIME="%DESIGNTIME%"

echo clean up VSIX folder contents
pause
del "%VSIXROOT%\SDKManifest.xml"
rd /q /S "%VSIXROOT%\References"
rd /q /S "%VSIXROOT%\Redist"
rd /q /S "%VSIXROOT%\Designtime"

echo Creating directories
md "%REFERENCES%"
md "%REDIST%"
md "%DESIGNTIME%"

echo Copying files

copy "%root%\%namespace%\SDKManifest.xml" "%VSIXROOT%"
xcopy /diskey "%root%\%namespace%\Themes" "%REDIST%\Themes"
copy "%root%\%namespace%\bin\%config%\%namespace%.pri" "%REDIST%"
copy "%root%\%namespace%\bin\%config%\%namespace%.dll" "%REFERENCES%"
copy "%root%\%namespace%.design\bin\%config%\%namespace%.design.dll" "%DESIGNTIME%"

if "%DEP1%" NEQ "" ( copy "%DEP1%" "%REFERENCES%" )
if "%DEP2%" NEQ "" ( copy "%DEP2%" "%REFERENCES%" )

if %ERRORLEVEL% EQU 0 (
	echo UpdateVSIX Succeeded
) else (
	echo UpdateVSIX FAILED
)
